﻿/******************************************************************
** auth: wei.huazhong
** date: 8/14/2020 17:10:19
** desc:
******************************************************************/

using System;
using System.Collections.Generic;
using static System.String;
using System.Text;
using IServices;
using Models;
using System.IdentityModel.Tokens.Jwt;
using Microsoft.Extensions.Options;
using System.Linq;
using DAL;

namespace Services
{
    public class UserService : IUserService
    {
        private MockDAL _dal;
        public UserService(MockDAL dal)
        {
            _dal = dal;
        }

        public User GetByID(int id)
        {
            return _dal.GetUserByID(id);
        }

        public User GetByName(string name)
        {
            return _dal.GetUserByName(name);
        }

        public UserPermissionVM GetUserPermissionVM(int userID)
        {
            var user = GetByID(userID);
            var roles = _dal.GetRolesByUserID(userID);
            return new UserPermissionVM { Name = user.Name, Avatar = user.Avatar, Roles = Join(",", roles.Select(m => m.Name)) };
        }
    }
}
